﻿using System;
using System.Collections.Generic;
using PluginService.DB.Model;
using NetBrother.TopShow;
using PluginService.Base;

namespace PluginService.DB.Dao
{
	/// <summary>
	/// BlankFeatureDao
	/// </summary>
	public class BlankFeatureDao : MyBatisDaoBase<BlankFeature>
	{
		
		#region 构造函数



        public BlankFeatureDao()
            : base("SqlMap.Config", "SqlMap.Config")
        {

        }

        //public BlankFeatureDao()
        //    : base(new Uri(string.Format("http://{0}/{1}", Consts.WEBSERVER_URL, "get_db_sqlmap")) { }, new Uri(string.Format("http://{0}/{1}", Consts.WEBSERVER_URL, "get_db_sqlmap")) { })
        //{ }
		public BlankFeatureDao(string read, string writer) : base(read, writer) { }
		#endregion

		#region 方法
		/// <summary>
		/// 获取BlankFeature
		/// </summary>
		/// <param name="id">Id</param>
		/// <returns>BlankFeature</returns>
		public BlankFeature GetBlankFeature(System.Int64 id)
		{
			return Reader.QueryForObject<BlankFeature>(GetStatementName("GetBlankFeature"), id);
		}

        public BlankFeature GetBlankFeatureByGuid(System.String guid)
        {
            return Reader.QueryForObject<BlankFeature>(GetStatementName("GetBlankFeatureByGuid"), guid);
        }

		/// <summary>
		/// 获取BlankFeature集合
		/// </summary>
		/// <param name="blankFeatureQp">BlankFeature</param>
		/// <returns>BlankFeature集合</returns>
		public IList<BlankFeature> GetBlankFeatures(BlankFeatureQP blankFeatureQp)
		{
			if(blankFeatureQp.IsReset)
            {
                blankFeatureQp.PageIndex = 1;
            }
			blankFeatureQp.ItemCount = GetBlankFeaturesCount(blankFeatureQp);
			return Reader.QueryForList<BlankFeature>(GetStatementName("GetBlankFeatures"), blankFeatureQp);
		}

        public IList<BlankFeature> GetBlankFeaturesNoImages(BlankFeatureQP blankFeatureQp)
        {
            if (blankFeatureQp.IsReset)
            {
                blankFeatureQp.PageIndex = 1;
            }
            blankFeatureQp.ItemCount = GetBlankFeaturesCount(blankFeatureQp);
            return Reader.QueryForList<BlankFeature>(GetStatementName("GetBlankFeaturesNoImages"), blankFeatureQp);
        }
		
		/// <summary>
		/// 获取BlankFeature 记录数
		/// </summary>
		/// <param name="blankFeatureQp">query</param>
		/// <returns>BlankFeature集合</returns>
		public int GetBlankFeaturesCount(BlankFeatureQP blankFeatureQp)
		{
			return Reader.QueryForObject<int>(GetStatementName("GetBlankFeaturesCount"), blankFeatureQp);
		}

		/// <summary>
		/// 有否BlankFeature
		/// </summary>
		/// <param name="id">Id</param>
		/// <returns>结果</returns>
		public bool HasBlankFeature(System.Int64 id)
		{
			return Reader.QueryForObject<int>(GetStatementName("HasBlankFeature"), id) > 0;
		}

		/// <summary>
		/// 插入BlankFeature
		/// </summary>
		/// <param name="blankFeature">BlankFeature</param>
		/// <returns>结果</returns>
		public int InsertBlankFeature(BlankFeature blankFeature)
		{
			var rst = Writer.Insert(GetStatementName("InsertBlankFeature"), blankFeature);
			return (int)(rst??0);
		}

		///<summary>
		///删除BlankFeature
		///</summary>
		///<param name="id">Id</param>
		///<returns>结果</returns>
		public bool RemoveBlankFeature(System.Int64 id)
		{
			return Writer.Update(GetStatementName("RemoveBlankFeature"), id) > 0;
		}

        public bool DelBlankByGuid(System.String guid)
        {
            return Writer.Update(GetStatementName("DelBlankByGuid"), guid) > 0;
        }

        public bool ClearBlankFeature()
        {
            return Writer.Delete(GetStatementName("ClearBlankFeature"), null) > 0;
        }
	
		/// <summary>
		/// 更新BlankFeature
		/// </summary>
		/// <param name="blankFeatureQp">BlankFeature</param>
		/// <returns>结果</returns>
		public bool UpdateBlankFeature(BlankFeatureQP blankFeatureQp)
		{
			return Writer.Update(GetStatementName("UpdateBlankFeature"), blankFeatureQp) > 0;
		}
		#endregion
	}
}

